package com.nlx.notes.module.mapper.loan;

import com.nlx.notes.module.bean.bo.LoanDetailBO;
import com.nlx.notes.module.bean.dto.loan.LoanDetailQueryDTO;
import com.nlx.notes.module.entity.LoanDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author nlx
 * @since 2025-10-25
 */
public interface LoanDetailMapper extends BaseMapper<LoanDetail> {

    long countByCondition(LoanDetailQueryDTO loanDetailQueryDTO);

    List<LoanDetailBO> selectPageByCondition(LoanDetailQueryDTO loanDetailQueryDTO);

    @Select(" select * from loan_detail where id = #{id} and user_id = #{userId} and del_flag = 0 ")
    LoanDetail findById(@Param("id") Long id, @Param("userId") Long userId);

    @Select(" select sum(amount) from loan_detail where summary_id = #{summaryId} and type = #{type} and del_flag = 0 ")
    Integer sumLoanDetail(@Param("summaryId") Long summaryId, @Param("type") String type);

    @Select(" select flow_id from loan_detail where summary_id = #{summaryId} and user_id = #{userId} and del_flag = 0")
    List<Long> findFlowIdsBySummaryId(@Param("summaryId") Long summaryId, @Param("userId") Long userId);
}
